import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_gradient_line.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_title_content_view.dart';
import 'package:enterprise_v6_app/app/components/video/fijkplayer_skin.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/common/personnel_type.dart';
import 'package:enterprise_v6_app/app/modules/application/special_operation/standing_book_page/operating_ledger_page/operating_ledger_details_page/operating_ledger_details_controller.dart';
import 'package:fijkplayer/fijkplayer.dart';

/// description: 作业台账详情页
class OperatingLedgerDetailsPage extends StatelessWidget {
  OperatingLedgerDetailsPage({super.key});

  final controller = Get.put(OperatingLedgerDetailsController());

  Widget _rows(
    String name,
  ) {
    return Container(
      height: 55.w,
      padding: EdgeInsets.symmetric(horizontal: 12.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            name,
            style: TextStyle(
              fontSize: 15.sp,
              color: Colors.black,
            ),
          ),
          Container(
            width: 20.w,
            height: 20.w,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(4.w),
              color: const Color(0x1F5C6DFF),
            ),
            child: Icon(
              Icons.arrow_forward,
              size: 14.w,
              color: const Color(0xFF5C6DFF),
            ),
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[100],
      appBar: CustomAppBar(
        iconButtonColor: Colors.white,
        leading: const BackButton(
          color: Colors.white,
        ),
        title: Text(
          '作业详情',
          style: TextStyle(
            fontSize: 16.sp,
            color: Colors.white,
            fontWeight: FontWeight.w500,
          ),
        ),
        backgroundColor: const Color(0xFF5C6DFF),
      ),
      body: GetBuilder(
        init: controller,
        builder: (_) {
          return Stack(
            children: [
              Container(
                height: 185.w,
                width: double.infinity,
                padding: EdgeInsets.only(
                  left: 17.w,
                  right: 17.w,
                  top: 24.w,
                ),
                color: const Color(0xFF5C6DFF),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      children: [
                        Container(
                            height: 20.w,
                            width: 20.w,
                            padding: EdgeInsets.all(4.w),
                            decoration: BoxDecoration(
                              color: const Color(0x1Fffffff),
                              borderRadius: BorderRadius.circular(4.w),
                            ),
                            child: Icon(
                              Icons.person,
                              size: 12.w,
                              color: Colors.white,
                            )),
                        AppGaps.hGap8,
                        Text(
                          controller.receiptInfoEntity.applyUserName ?? '',
                          style: TextStyle(
                            fontSize: 12.sp,
                            color: Colors.white,
                          ),
                        ),
                        AppGaps.hGap6,
                        Expanded(
                          // child: Text('${controller.ticketReceiptList.startDate}\n至${controller.ticketReceiptList.endDate}',style: TextStyle(
                          child: Text(
                            '${controller.ticketReceiptList.startDate}',
                            style: TextStyle(
                              fontSize: 12.sp,
                              color: Colors.white,
                            ),
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 5.w),
                          decoration: BoxDecoration(
                            color: const Color(0x1Fffffff),
                            borderRadius: BorderRadius.circular(14.w),
                          ),
                          child: Row(
                            children: [
                              Text(
                                '作业票',
                                style: TextStyle(
                                  fontSize: 12.sp,
                                  color: Colors.white,
                                ),
                              ),
                              AppGaps.hGap6,
                              SvgPicture.asset(
                                AppImages.icon_job_right,
                                width: 14.w,
                                height: 14.w,
                              ),
                            ],
                          ),
                        ).click(controller.toJobTicket),
                      ],
                    ),
                    AppGaps.vGap5,
                    Text(
                      '作业地点：${controller.receiptInfoEntity.ticketAddress}',
                      style: TextStyle(
                        fontSize: 20.sp,
                        color: Colors.white,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    AppGaps.vGap12,
                    Text(
                      '作业内容：${controller.receiptInfoEntity.ticketContent?.trim()}',
                      style: TextStyle(
                        fontSize: 12.sp,
                        color: Colors.white,
                      ),
                    ),
                    AppGaps.vGap12,
                    Row(
                      children: [
                        Expanded(
                          child: Text(
                            '作业负责人：${PersonnelType.getNameByType(controller.receiptInfo.operatorLists!, type: 1)}',
                            style: TextStyle(
                              fontSize: 12.sp,
                              color: Colors.white,
                            ),
                          ),
                        ),
                        AppGaps.hGap40,
                        Expanded(
                          child: Text(
                            '验收人：${PersonnelType.getNameByType(controller.receiptInfo.operatorLists!, type: 9)}',
                            style: TextStyle(
                              fontSize: 12.sp,
                              color: Colors.white,
                            ),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              Container(
                margin: EdgeInsets.only(top: 164.w),
                padding: EdgeInsets.only(
                  left: 16.w,
                  right: 16.w,
                ),
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      CustomTitleContentView(
                        title: Row(
                          children: [
                            SvgPicture.asset(
                              AppImages.icon_title,
                              width: 20.w,
                              height: 20.w,
                            ),
                            Container(
                              margin: EdgeInsets.only(left: 6.w),
                              child: Text(
                                '作业来源',
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: Colors.black,
                                  fontSize: 15.sp,
                                  fontWeight: FontWeight.w500,
                                ),
                              ),
                            ),
                          ],
                        ),
                        content: Container(
                          alignment: Alignment.centerLeft,
                          padding: EdgeInsets.symmetric(horizontal: 12.w),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              Text(
                                controller.receiptInfoEntity.ticketSource!.isEmpty ? '作业计划' : controller.receiptInfoEntity.ticketSource!,
                                style: TextStyle(
                                  fontSize: 13.sp,
                                  color: Colors.grey,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                      // AppGaps.vGap16,
                      // CustomTitleContentView(
                      //   title: Row(
                      //     children: [
                      //       SvgPicture.asset(
                      //         AppImages.icon_title,
                      //         width: 20.w,
                      //         height: 20.w,
                      //       ),
                      //       Container(
                      //         margin: EdgeInsets.only(left: 6.w),
                      //         child: Text(
                      //           '作业公司：${controller.receiptInfoEntity.receiptInfo?.ticketReceiptList?.workDepartmentName}',
                      //           overflow: TextOverflow.ellipsis,
                      //           style: TextStyle(
                      //             color: Colors.black,
                      //             fontSize: 15.sp,
                      //             fontWeight: FontWeight.w500,
                      //           ),
                      //         ),
                      //       ),
                      //       const Spacer(),
                      //       Container(
                      //         width: 20.w,
                      //         height: 20.w,
                      //         margin: EdgeInsets.only(right: 12.w),
                      //         decoration: BoxDecoration(
                      //           borderRadius: BorderRadius.circular(4.w),
                      //           color: const Color(0x1F5C6DFF),
                      //         ),
                      //         child: Icon(Icons.arrow_forward,size: 14.w,color: const Color(0xFF5C6DFF),),
                      //       )
                      //     ],
                      //   ).click(controller.toCompanyDetails),
                      //   content: ListView.separated(
                      //       itemCount: controller.companyList.length,
                      //       shrinkWrap: true,
                      //       physics: const NeverScrollableScrollPhysics(),
                      //       itemBuilder: (context,index) {
                      //         return _rows(controller.companyList[index]).click((){
                      //           controller.toCompanyList(index);
                      //         });
                      //       },
                      //       separatorBuilder: (context,index) {
                      //         return const CustomGradientLine();
                      //       }
                      //   ),
                      // ),
                      AppGaps.vGap16,
                      CustomTitleContentView(
                        title: Row(
                          children: [
                            SvgPicture.asset(
                              AppImages.icon_title,
                              width: 20.w,
                              height: 20.w,
                            ),
                            Container(
                              margin: EdgeInsets.only(left: 6.w),
                              child: Text(
                                '作业附件',
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: Colors.black,
                                  fontSize: 15.sp,
                                  fontWeight: FontWeight.w500,
                                ),
                              ),
                            ),
                          ],
                        ),
                        content: ListView.separated(
                            itemCount: controller.companyAttachmentList.length,
                            shrinkWrap: true,
                            physics: const NeverScrollableScrollPhysics(),
                            itemBuilder: (context, index) {
                              return _rows(controller.companyAttachmentList[index]).click(() {
                                controller.toCompanyAttachmentList(controller.companyAttachmentList[index]);
                              });
                            },
                            separatorBuilder: (context, index) {
                              return const CustomGradientLine();
                            }),
                      ),
                      AppGaps.vGap16,
                      CustomTitleContentView(
                        title: Row(
                          children: [
                            SvgPicture.asset(
                              AppImages.icon_title,
                              width: 20.w,
                              height: 20.w,
                            ),
                            Container(
                              margin: EdgeInsets.only(left: 6.w),
                              child: Text(
                                '作业录像',
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: Colors.black,
                                  fontSize: 15.sp,
                                  fontWeight: FontWeight.w500,
                                ),
                              ),
                            ),
                          ],
                        ),
                        content: Container(
                          alignment: Alignment.center,
                          width: MediaQuery.of(context).size.width,
                          height: MediaQuery.of(context).size.width * 9 / 16,
                          child: controller.videoSourceTabs != null ? FijkView(
                            color: Colors.black,
                            player: controller.player,
                              panelBuilder: (FijkPlayer player, FijkData data, BuildContext context, Size viewSize, Rect texturePos,) {
                                return CustomFijkPanel(
                                  player: player,
                                  // 传递 context 用于左上角返回箭头关闭当前页面，不要传递错误 context，
                                  // 如果要点击箭头关闭当前的页面，那必须传递当前组件的根 context
                                  pageContent: context,
                                  viewSize: viewSize,
                                  texturePos: texturePos,
                                  // 当前视频改变钩子，简单模式，单个视频播放，可以不传
                                  onChangeVideo: controller.onChangeVideo,
                                  playerTitle: '',
                                  // 当前视频源tabIndex
                                  curTabIdx: controller.curTabIdx,
                                  // 当前视频源activeIndex
                                  curActiveIdx: controller.curActiveIdx,
                                  // 显示的配置
                                  showConfig: controller.vCfg,
                                  // json格式化后的视频数据
                                  videoFormat: controller.videoSourceTabs,
                                );
                              }
                          ) : Container(
                            alignment: Alignment.center,
                            child: Text(
                              '暂无视频',
                              style: TextStyle(
                                fontSize: 12.sp,
                                color: Colors.grey,
                              ),
                            ),
                          ),
                        ),
                      ),
                      AppGaps.vGap12,
                      // Wrap(
                      //   runSpacing: 10.w,
                      //   spacing: 10.w,
                      //   children: List.generate(controller.videoSourceTabs.video![0]!.list!.length, (index) {
                      //     return Container(
                      //             width: 80.w,
                      //             height: 35.w,
                      //             alignment: Alignment.center,
                      //             decoration: BoxDecoration(
                      //               color: controller.videoIndex == index ? AppColors.blue_button : Colors.grey[300],
                      //               borderRadius: BorderRadius.circular(10.w),
                      //             ),
                      //             child: Text('视频${index + 1}')).click(() {
                      //       controller.changeVideo(index);
                      //     });
                      //   }),
                      // ),
                      AppGaps.vGap28,
                    ],
                  ),
                ),
              )
            ],
          );
        },
      ),
    );
  }

}
